package models

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

var (
	MysqlDb map[string]*sql.DB
)

func init() {
	d := NewMysqlDb("root", "123qwe", "127.0.0.1", 3306, "information_schema")
	MysqlDb = make(map[string]*sql.DB)
	MysqlDb["information_schema"] = d
}
func NewMysqlDb(usr, pwd, host string, port int, dbName string) *sql.DB {
	constr := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8", usr, pwd, host, port, dbName)
	db, err := sql.Open("mysql", constr)
	if err != nil {
		panic(err.Error())
	}
	db.SetMaxOpenConns(3000)
	db.SetMaxIdleConns(1000)
	return db
}
